package com.cy.store.config;

import com.cy.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 登录拦截器配置类
 */
@Configuration
public class LoginInterceptorConfigure implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //初始化登录拦截器对象
        LoginInterceptor loginInterceptor = new LoginInterceptor();
        //存放白名单路径字符串
        List<String> list = new ArrayList<>();
        list.add("/bootstrap3/**");
        list.add("/css/**");
        list.add("/images/**");
        list.add("/js/**");
        list.add("/web/login.html");
        list.add("/web/register.html");
        list.add("/web/index.html");
        list.add("/web/product.html");
        list.add("/user/reg");
        list.add("/user/login");
        list.add("/district");
        list.add("/address");
        list.add("/product/**");

        //注册登录拦截器并配置黑白名单
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//拦截的地址路径
                .excludePathPatterns(list);//不拦截的地址路径
    }
}
